import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '@/views/home/Home.vue'
import Login from '@/views/login/Login.vue'
import NotFound from '@/components/NotFound'
const routerPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
	return routerPush.call(this, location).catch(error => error)
}

Vue.use(VueRouter)

// route level code-splitting
// this generates a separate chunk (chunkName.[hash].js) for this route
// which is lazy-loaded when the route is visited.

const SendPaySlip = () =>
	import(/* webpackChunkName: "paySlip" */ '@/views/pay-slip/SendPaySlip.vue')
const PaySlipManagement = () =>
	import(/* webpackChunkName: "paySlip" */ '@/views/pay-slip/PaySlipManagement.vue')
const PreviewPaySlip = () =>
	import(/* webpackChunkName: "paySlip" */ '@/views/pay-slip/PreviewPaySlip.vue')
const PaySlipSetting = () =>
	import(/* webpackChunkName: "paySlip" */ '@/views/pay-slip/PaySlipSetting.vue')

const routes = [
	{
		path: '*',
		component: NotFound,
		name: 'Notfound',
		meta: {
			title: '404'
		}
	},
	{
		path: '/',
		redirect: '/home'
	},
	{
		path: '/home',
		name: 'Home',
		component: Home,
		meta: {
			title: '首页'
		}
	},
	{
		path: '/login',
		name: 'Login',
		component: Login,
		meta: {
			title: '登录'
		}
	},
	{
		path: '/sendPaySlip',
		name: 'SendPaySlip',
		component: SendPaySlip,
		meta: {
			title: '发工资条',
			requiresAuth: true
		}
	},
	{
		path: '/paySlipManagement',
		name: 'PaySlipManagement',
		component: PaySlipManagement,
		meta: {
			title: '工资条管理',
			requiresAuth: true
		}
	},
	{
		path: '/paySlipManagement/PreviewPaySlip/:id',
		name: 'PreviewPaySlip',
		component: PreviewPaySlip,
		meta: {
			title: '工资条详情',
			requiresAuth: true,
			activeLabel: '工资条管理',
			activeMenu: '/paySlipManagement'
		}
	},
	{
		path: '/paySlipSetting',
		name: 'PaySlipSetting',
		component: PaySlipSetting,
		meta: {
			title: '工资条设置',
			requiresAuth: true
		}
	}
]

const router = new VueRouter({
	mode: 'history',
	base: process.env.BASE_URL,
	routes
})

export default router
